/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package br.com.ufc.quixada.dao;

import br.com.ufc.quixada.entidades.Aluguel;
import br.com.ufc.quixada.util.ConnectionFactory;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Administrator
 */
public class AluguelDAO {
    
    private Connection con;
    
    public AluguelDAO() throws ClassNotFoundException {
        con = new ConnectionFactory().getConnection();
    }
    
    public void destroy() {
        try {
            con.close();
        } catch (SQLException ex) {
            Logger.getLogger(ClientesDAO.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    
    public void inserirAluguel(Aluguel aluguel) throws SQLException {
        PreparedStatement stmt = null;

        try {
            String sql = "INSERT INTO aluguel (codigocliente, codigodoexemplar, dataentrega, datadevolucao, valortotal) VALUES (?,?,?,?,?)";
            stmt = con.prepareStatement(sql);

            stmt.setString(1, aluguel.getCpfcliente());
            stmt.setLong(2, aluguel.getCodigodoexeplar());
            stmt.setString(3, aluguel.getDataentrega());
            stmt.setString(4, aluguel.getDatadevolucao());
            stmt.setDouble(5, aluguel.getValortotal());
            

            stmt.execute();


        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            if (con != null) {
                con.close();
            }
            if (stmt != null) {
                stmt.close();
            }
        }
    }
    
}
